package Login.servlet;

import Login.util.CountUtils;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRequestEvent;
import javax.servlet.ServletRequestListener;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpSessionEvent;
import javax.servlet.http.HttpSessionListener;

@WebServlet(name = "MyListener", urlPatterns = "/listener")
public class MyListener implements ServletContextListener, HttpSessionListener, ServletRequestListener {
    @Override
    public void contextInitialized(ServletContextEvent arg0) {
        System.out.println("ServletContext对象被创建了");
    }
    @Override
    public void contextDestroyed(ServletContextEvent arg0) {
        System.out.println("ServletContext对象被销毁了");
    }
    @Override
    public void requestInitialized(ServletRequestEvent arg0) {
        System.out.println("ServletRequest对象被创建了");
    }
    @Override
    public void requestDestroyed(ServletRequestEvent arg0) {
        System.out.println("ServletRequest对象被销毁了");
    }
    @Override
    public void sessionCreated(HttpSessionEvent arg0) {
        System.out.println("HttpSession对象被创建了");
        CountUtils.add();
    }
    @Override
    public void sessionDestroyed(HttpSessionEvent arg0) {
        System.out.println("HttpSession对象被销毁了");
        CountUtils.subtract();
    }
}
